<?php
require_once 'index1.php';
require_once 'class/staff.php';
if (isset($_SESSION['staff'])) {
    $staff = unserialize($_SESSION['staff']);
    ?>
    <link rel="stylesheet" href="/css/jquery-ui.css"/>
    <script src="/libs/jquery-1.9.1.js"></script>
    <script src="/libs/jquery-ui.js"></script>
    <script>
        $(document).ready(function(){
            $("#progressbar").progressbar({value:0});
            $( "#accordion" ).accordion({ collapsible: true },{ active: 2 },{ event: "mouseover" });
        });
                    
        function submitArray(){
            $.post("ajax3.php", $("#dutyArray").serialize(), function(data){$("#fd").html(data)});
            setTimeout(function(){$("#progressbar").hide();
                $( "#progressbar" ).progressbar( "option", "value", 100 );
                $( "#progressbar" ).fadeIn("slow");
                $("#test1").hide();
                $("#content1").hide();
            },2000);
            setTimeout(function(){
                if($("#fd").text()=="initial successful"){
               window.location.assign("http://localhost:8080/staff.php"); 
            }
            },3000);
            
        }
        
    </script>
    <div id="progressbar"></div>
    <?php
    echo "<div class='logStatuebar'><span class='welcome'> welcome staff</span>";
    echo "<div class=logout><a href='logout.php?attempt'>Log Out</a></div>";
    echo "<div class='userName'>" . $staff->getEmail() . "</div></div>";
    echo "1.initial duties<br>";
    echo "2.initial except dates<br>";
    ?>
    <div id="fd">here</div>
    <div id="accordion">
        <h3 id="test1">select duty</h3>
        <div id="content1">
            <form id="dutyArray">
                <select name="dutyArray[]" multiple>
                    <?php
                    $staffTemp = new staff($staff->getEmail(),$staff->getPW());
                    $dutyA = $staffTemp->fetchDutyArray();
                    foreach ($dutyA as $value) {
                        echo "<option value='".$value['dutyName']."'>".$value['dutyName']."</option>";
                    }
                    ?>
                </select>
                <select name="ExceptDateArray[]" multiple>
                    <?php
                    $exceptA = $staffTemp->fetchSundayArray();
                    foreach ($exceptA as $value) {
                        echo "<option value='".$value['Date']."'>".$value['Date']."</option>";
                    }
                    ?>
                </select>
            </form>
            <button type="submit" onclick="submitArray()">submit</button>
        </div>
        
    </div>
    <?php
} else {
    echo 'you need to login first';
    header("refresh:2; url=http://localhost:8080");
}
require_once 'index2.php';
?>
